home *** CD-ROM | disk | FTP | other *** search
- #! /usr/bin/perl5
- #
- # htnetwork
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: htnetwork,v 1.5 1997/04/17 23:38:16 shotes Exp $
-
- #
- # Simple script to parse the output of netstat and ifconfig and provide
- # a table of the results.
- #
-
- open(NS, "/usr/etc/netstat -in|");
- $index = 0;
- while (<NS>) {
- if ($index == 0) { # skip row of headers
- $index++;
- next;
- }
-
- next if ($_ =~ /^\s/); # skip alias rows
-
- # These are fixed length fields.
- $one = substr($_, 0, 5);
- $up = ($one =~ /\*\s*$/) ? 0 : 1;
- $one =~ /\*|\s/;
- $ifname = $`;
-
- next if ($ifname =~ /^lo/); # skip loopback
-
- $data = join(' ',`/usr/etc/ifconfig $ifname`);
- $ip = ($data =~ /inet (\d+\.\d+\.\d+\.\d+)/) ? $1 : "";
- $netmask = ($data =~ /netmask (\S+)/) ? $1 : "";
-
- ($hostname,$dm1,$dm2,$dm3,@dm4) =
- (gethostbyaddr(pack('C4', split(/\./, $ip)),2));
-
- printf("%d:%s:%d:%s:%s:%s\n", $index, $ifname, $up, $ip, $netmask,
- $hostname);
-
- $index++;
- }
- close(NS);
-